$(function () {
    $('[data-toggle="tooltip"]').tooltip();
    CheckImgExists();
    //获取待办事项
    setTimeout(function () {
        getBacklogCount(function (count) {
            $("#sumBacklogNum").removeClass("hide");
            $("#sumBacklogNum").text(count);
        });
    },300);

    $("body").on('click',"#update-pwd-box",function () {
        var context = '<div class="m-t m-r m-l m-b">' +
            '原密码：<input class="form-control" id="oldPassword" type="password">' +
            '</div>'+
            '<div class="m-t m-r m-l m-b">' +
            '新密码：<input class="form-control" id="newPassword" type="password">' +
            '</div>'+
            '<div class="m-t m-r m-l m-b">' +
            '确认密码：<input class="form-control" id="confirmPassword" type="password">' +
            '</div>';
        parent.layer.open({
            type: 1,
            area: ['380px'],
            skin: 'layui-layer-demo',
            title: '修改密码',
            content:context ,
            btn: '确定',
            yes: function (index, layero) {
                var oldPassword = layero.find('#oldPassword').val();
                var newPassword = layero.find('#newPassword').val();
                var confirmPassword = layero.find('#confirmPassword').val();

                $.ajax({
                    url: baseloaction +'/admin/updateThisPwd',
                    type:'post',
                    dataType:'json',
                    data:{
                        'oldPassword':oldPassword,
                        'newPassword':newPassword,
                        'confirmPassword':confirmPassword
                    },
                    success:function (result) {
                        icModale(0,result.message);
                        if(result.success==true){
                            parent.layer.close(index);
                            setTimeout(function () {
                                window.location.href = baseloaction + '/logout';
                            },2500);
                        }
                    },
                    error:function (error) {
                        icModale(0,"系统错误，修改密码失败");
                    }
                });
            }
        });
    }).on('click','#to-do-list-box',function () {//点击右则的待办事项
        getRedirectMenu(baseloaction+'/admin/manage/work/myBacklog',false);
    }).on('click','#index-online-consultation',function () {
        var content = $(this).data('consultation');
        window.open(content,'newwindow', 'toolbar=no,scrollbars=yes,location=no,resizable=no,top=200,left=300,width=800,height=600');
    });

    function CheckImgExists() {
        var imgurl = $(".img-circle").attr('src');
        var ImgObj = new Image(); //判断图片是否存在
        ImgObj.src = imgurl;
        //没有图片，则返回-1
        if (ImgObj.fileSize > 0 || (ImgObj.width > 0 && ImgObj.height > 0)) {
            return true;
        } else {
            $(".img-circle").attr('src',staticPath+'/admin/v3/img/default/admin_userpace.jpg');
            return false;
        }
    }
});

/**
 * 获取待办事项的数量
 */
function getBacklogCount(callback){
    $.ajax({
        url: baseloaction +'/admin/manage/work/getBacklogCount',
        type:'post',
        dataType:'json',
        success:function (result) {
            if(result.success==true){
                var count = result.entity;
                if($.isFunction(callback)){
                    callback(count);
                }
            }
        }
    });
}

